package jp.co.lty.mai;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import jp.co.lty.mai.meta.WorkingSheetMeta;
import jp.co.lty.mai.model.WorkingSheet;
import jp.co.lty.mai.service.WorkSheetService;

import org.pirkaengine.core.PirkaException;
import org.pirkaengine.slim3.PirkaPage;
import org.slim3.controller.Navigation;
import org.slim3.datastore.Datastore;
import org.slim3.util.RequestMap;

import scenic3.annotation.ActionPath;
import scenic3.annotation.Default;
import scenic3.annotation.Page;

@Page("/worksheet")
public class WorkSheetPage extends PirkaPage {
    private WorkSheetService service = new WorkSheetService();

    @Default
    public Navigation index() throws PirkaException, IOException {
        WorkingSheetMeta wMeta = new WorkingSheetMeta();
        List<WorkingSheet> list = Datastore.query(wMeta).sort(wMeta.date.asc).asList();

        viewModel("list", list);
        return render("workingsheet.html");
    }

    // save
    @ActionPath("save")
    public Navigation tweet() {
        service.save(new RequestMap(request));
        return redirect(basePath);
    }

}
// AppUrlsには手動でMatcherを登録する必要がある。
